package test2;

import java.util.Arrays;
import java.util.Scanner;
public class Main{
	class PersonSortable implements Comparable<PersonSortable> {
		private String name;
		private int age;

		public String toString() {
			return "PersonSortable [name=" + name + ", age=" + age + "]";
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getAge() {
			return age;
		}

		public void setAge(int age) {
			this.age = age;
		}

		public PersonSortable(String name, int age) {
			this.name = name;
			this.age = age;
		}

		public  static void main(String[] args) {
			int n;
			Scanner sc = new Scanner(System.in);
			n = sc.nextInt();
			PersonSortable[] s = new PersonSortable[n];
			for (int i = 0; i < n; i++) {
				String name = sc.next();
				int age = sc.nextInt();
				s[i] = new PersonSortable(name, age);
			}
			Arrays.sort(s);
			for (int i = 0; i < n; i++) {
				System.out.println(s[i].toString());
			}
			System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		}

	@Override
	public int compareTo(PersonSortable o) {
		   if (this.name.compareTo(o.name) == 0)
		        return this.getAge() - o.getAge();
		    if (this.name.compareTo(o.name) > 0) {
		        return 1;
		    }
		    if (this.name.compareTo(o.name) < 0) {
		        return -1;
		    }
		    return 0;
		
	}
}
}
